package com.example.service.impl;

import com.example.entity.User;
import com.example.mapper.UserDao;
import com.example.service.SubUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author houyangfan
 * @version 1.0
 * @date 2022/7/18 17:39
 */
@Service
public class SubUserServiceImpl implements SubUserService {

    @Autowired
    private UserDao userDao;

    @Override
    // 该参数的作用是执行到这个方法的时候开启新的事务，并挂起当前的事务
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void createSubUser(User user) {
        userDao.insert(user);
        throw new RuntimeException("sub user create fail");

    }
}
